package cn.edu.ylu.gaoxin.controller;

import com.jfinal.core.ActionKey;
import com.jfinal.core.Controller;
import com.jfinal.ext.kit.SessionIdKit;

import cn.edu.ylu.gaoxin.model.User;

/**
 * 		用户控制器
 *		abc.com/user/123
 */
public class UserController extends Controller {
	public void index(){
		String user_id = getPara(0);
		User user = User.dao.findByUserId(user_id);
		setAttr("user",user);
		render("/user/index.html");
		
		
	}
	
	//修改密码
	public void changepwd(){
	}
	//找回密码
	public void findpwd(){
	}
	
	//
	@ActionKey("/user/regist")
	public void regist(){
		User user = new User(this.getRequest());
//		//Jfinal create unique id
		user.setUserId(SessionIdKit.me().generate(this.getRequest()));
		user.setEmail(getPara("email"));
		user.setUserName(getPara("user_name"));
		user.setPassword(getPara("password"));
		
		if(user.insert(user)){
			setAttr("code",1);
			setAttr("user_id",user.getUserId());
		}else{
			setAttr("code",0);
		}
		renderJson();
	}
	
}
